package cn.lan.generator.bean;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.lan.generator.utils.ConfigUtil;
import cn.lan.generator.utils.Constant;

/**
 * @author lanping
 * @version 1.0
 * @date 2019-06-30
 **/
public class ProjInfo {

    /**
     * 项目名称 如 homi-recycle
     */
    private String projectName;

    /**
     * 项目简写 如 homi
     */
    private String projectSimpleName;


    /**
     * 业务模块名称 统一 module-{moduleName}
     * 例如 module-order 此时moduleName ="order"
     */
    private String moduleName;

    /**
     * 是否创建service pom.xml
     */
    private boolean createModulePomXml;

    /**
     * 项目系统名称 例如 xxx管理系统
     */
    private String projectSysName;

    /**
     * 端口 默认8080
     */
    private int port=8080;

    /**
     * 项目包名 com.logicalthinking.base
     */
    private String packageName;

    /**
     * 开发者名称
     */
    private String author;

    /**
     * 开发者邮箱
     */
    private String authorEmail;

    /**
     * 是否生成前端页面 默认不生成
     */
    private boolean thymeleaf = false;

    /**
     * 生成项目地址
     */
    private String createProjectUrl;

    /**
     * 基础访问路径
     */
    private String accessBaseUrl;

    /**
     * 是否生成zip
     */
    private boolean isCreateZIPFile;

    /**
     * 是否调试模式
     * 调试模式 为true时 模板文件路径为项目目录的target下，false时 模板文件路径为templateDir
     */
    private boolean debugModel = true;

    public String getAuthorEmail() {
        return ObjectUtil.isNotEmpty(authorEmail) ? authorEmail : ConfigUtil.getConfigValue(Constant.KEY_DEFAULT_AUTH_EMAIL);
    }

    public void setAuthorEmail(String authorEmail) {
        this.authorEmail = authorEmail;
    }

    public String getModuleName() {
        return moduleName;
    }

    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }

    public boolean isDebugModel() {
        return debugModel;
    }

    public void setDebugModel(boolean debugModel) {
        this.debugModel = debugModel;
    }

    public boolean isCreateModulePomXml() {
        return createModulePomXml;
    }

    public void setCreateModulePomXml(boolean createModulePomXml) {
        this.createModulePomXml = createModulePomXml;
    }

    public ProjInfo() {
    }

    public String getAccessBaseUrl() {
        if(StrUtil.isBlank(accessBaseUrl)){
            accessBaseUrl = ConfigUtil.getConfigValue(Constant.KEY_ACCESS_BASE_URL);
        }
        return accessBaseUrl;
    }

    public void setAccessBaseUrl(String accessBaseUrl) {
        this.accessBaseUrl = accessBaseUrl;
    }

    public String getCreateProjectUrl() {
        if(StrUtil.isBlank(createProjectUrl)){
            createProjectUrl = ConfigUtil.getConfigValue(Constant.KEY_CREATE_PROJ_URL);
        }
        return createProjectUrl;
    }

    public void setCreateProjectUrl(String createProjectUrl) {
        this.createProjectUrl = createProjectUrl;
    }

    public boolean isCreateZIPFile() {
        if(isCreateZIPFile==false){
            String createZip = ConfigUtil.getConfigValue(Constant.KEY_IS_CREATE_ZIP_FILE);
            if(Constant.IS_TRUE.equals(createZip)){
                isCreateZIPFile = true;
            }
        }
        return isCreateZIPFile;
    }

    public void setCreateZIPFile(boolean createZIPFile) {
        isCreateZIPFile = createZIPFile;
    }

    public String getProjectSimpleName() {
        return projectSimpleName;
    }

    public void setProjectSimpleName(String projectSimpleName) {
        this.projectSimpleName = projectSimpleName;
    }

    public String getProjectSysName() {
        return ObjectUtil.isNotEmpty(projectSysName)?
                projectSysName:projectName;
    }

    public void setProjectSysName(String projectSysName) {
        this.projectSysName = projectSysName;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public boolean isThymeleaf() {
        return thymeleaf;
    }

    public void setThymeleaf(boolean thymeleaf) {
        this.thymeleaf = thymeleaf;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getPackageName() {
        return ObjectUtil.isNotEmpty(packageName) ? packageName : ConfigUtil.getConfigValue(Constant.KEY_DEFAULT_PACKAGE);
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

}
